//
//  BaseTableViewController.swift
//  SynWeibo
//
//  Created by 沈艳男 on 15/8/31.
//  Copyright © 2015年 沈艳男. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {

    // 定义用户的标记,作用就是用来判断用户是否登录
    var userLogon = UserAccountViewModel.sharedUserAccount.userLogon

    
    // 实例化用户登录试图，作用：每个自控制器都会调用这个VisitorLoginView
    var visirorView: VisitorLoginView?
    
    override func loadView() {
        userLogon ? super.loadView(): setUpVistorView()
    }
    
    // 设置访客的界面
    private func setUpVistorView(){
        // 替换窗口,
        visirorView = VisitorLoginView()
        view = visirorView
        // 设置view颜色
//        view.backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)
        
        // 设置导航控制器
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
        
        visirorView?.registerButton.addTarget(self, action: "visitorLoginViewWillRegister", forControlEvents: UIControlEvents.TouchUpInside)
        
        visirorView?.loginButton.addTarget(self, action: "visitorLoginViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)

    }
    
    func visitorLoginViewWillRegister() {
//        print(__FUNCTION__)
        
        
        
    }
    
    func visitorLoginViewWillLogin() {
//        print(__FUNCTION__)
        // 实例化身份验证的功能
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc);
        // 跳转
        presentViewController(nav, animated: true) { () -> Void in
            print("跳转成功")
        }

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

//    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
//        // #warning Incomplete implementation, return the number of sections
////        return
//    }
//
//    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        // #warning Incomplete implementation, return the number of rows
//        return 0
//    }

}
